/*
  Copyright (c) 2006-2009 by HAO jing <haojingus@gmail.com>
  This file is part of the SVG library. http://libsvg.googlecode.com

  This software is distributed under a license. The full license
  agreement can be found in the file LICENSE in this distribution.
  This software may not be copied, modified, sold or distributed
  other than expressed in the named license agreement.

  This software is distributed without any warranty.
*/

#ifndef SVGDOCUMENT_H__
#define SVGDOCUMENT_H__


#include "config.win.h"
#include "gloox.h"
#include "svgtag.h"
#include "taghandler.h"
#include "parser.h"
//#include <libxml/parser.h>
#include <iostream>
#include <string>


namespace gloox
{




typedef struct svgexception
{
	int erroron;
	char message[256];

} SvgException;



#define DOCUMENT_ROOT "svg"


class SVG_API SVGDocument : TagHandler
{
public:
	SVGDocument(void);
	virtual ~SVGDocument(void);

	virtual bool loadSVG(const std::string& docname);
	//void createDrawQueue();

	void registerLineFun(void (*pFun)(SVGPOINT,SVGPOINT,CSS))		{m_LineFun		=	(!m_LineFun)?pFun:m_LineFun;};
	void registerPointFun(void (*pFun)(SVGPOINT,CSS))				{m_PointFun		=	(!m_PointFun)?pFun:m_PointFun;};
	void registerRectFun(void (*pFun)(SVGPOINT,SVGPOINT,CSS))		{m_RectFun		=	(!m_RectFun)?pFun:m_RectFun;};
	void registerPolygonFun(void (*pFun)(SVGPOINT*,int,CSS))		{m_PolygonFun	=	(!m_PolygonFun)?pFun:m_PolygonFun;};
	void registerTextFun(void (*pFun)(SVGPOINT,std::string,CSS))	{m_TextFun		=	(!m_TextFun)?pFun:m_TextFun;};
	void registerDescFun(void (*pFun)(std::string))					{m_DescFun		=	(!m_DescFun?pFun:m_DescFun);};

	void registerHandleError(void (*pFun)(void*,SvgException))		{OnError		=	(!OnError)?pFun:OnError;};
	void registerHandleFinish(void (*pFun)(void*,SvgException))	{OnError		=	(!OnFinish)?pFun:OnFinish;};
	void registerHandleLoad(void (*pFun)(void*,SVGPOINT))	{OnLoad		=	(!OnLoad)?pFun:OnLoad;};
public:
	void handleTag( Tag* tag );
	Parser m_parser;

private:

	char *m_DocName;

	void (*m_LineFun)(SVGPOINT,SVGPOINT,CSS);
	void (*m_PointFun)(SVGPOINT,CSS);
	void (*m_RectFun)(SVGPOINT,SVGPOINT,CSS);
	void (*m_PolygonFun)(SVGPOINT*,int,CSS);
	void (*m_TextFun)(SVGPOINT,std::string,CSS);
	void (*m_CircleFun)(SVGPOINT,int,CSS);
	void (*m_DescFun)(std::string);


	void (*OnError)(void*,SvgException);
	void (*OnFinish)(void*,SvgException);
	void (*OnLoad)(void*,SVGPOINT);

	

};

}
#endif